<template>
  <div>
    <div>
      <el-descriptions title="融资需求详情" :column="2" border label-width="200">
        <!-- 第一行 -->
        <el-descriptions-item label="融资需求编号">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.applyNo }}
        </el-descriptions-item>
        <el-descriptions-item label="融资金额">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.applyAmountMin }}-{{ financingInfo.applyAmountMax }} 万元
        </el-descriptions-item>

        <!-- 第二行 -->
        <el-descriptions-item label="融资期限">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.maturityMin }}-{{ financingInfo.maturityMax }} 月
        </el-descriptions-item>
        <el-descriptions-item label="融资年利率">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.rateMin }}-{{ financingInfo.rateMax }} %
        </el-descriptions-item>

        <!-- 第三行 -->
        <el-descriptions-item label="期望到账时间">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.arrivalTimeType }}
        </el-descriptions-item>
        <el-descriptions-item label="担保类型">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.guaranteeType }}
        </el-descriptions-item>

        <!-- 第四行 -->
        <el-descriptions-item label="还款方式">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.repaymentType }}
        </el-descriptions-item>
        <el-descriptions-item label="融资产品">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.productName }}
        </el-descriptions-item>

        <!-- 第五行 -->
        <el-descriptions-item label="产品额度">
          <!-- 值将通过数据绑定插入 -->

        </el-descriptions-item>
        <el-descriptions-item label="产品期限">
          <!-- 值将通过数据绑定插入 -->
        </el-descriptions-item>

        <!-- 第六行 -->
        <el-descriptions-item label="产品利率范围">
          <!-- 值将通过数据绑定插入 -->
        </el-descriptions-item>
        <el-descriptions-item label="申请时间">
          <!-- 值将通过数据绑定插入 -->
          {{ financingInfo.createTime }}
        </el-descriptions-item>

        <!-- 注意：信用券字段未包含，因为它在要求中是"不包含值"且未在字段列表中明确列出作为需显示的项 -->
      </el-descriptions>
    </div>

    <el-tabs v-model="companyActive" class="mt-10" @tab-click="handleCompanyClick">
      <el-tab-pane label="基本信息" name="baseInfo">
        <el-descriptions label-width="200" title="企业基本信息" :column="2" border size="medium"
          class="mt-3 enterprise-descriptions">
          <!-- 第一行 -->
          <el-descriptions-item label="企业名称">
            {{ enterpriseInfo.enterpriseName }}
          </el-descriptions-item>
          <el-descriptions-item label="统一社会信用代码">
            {{ enterpriseInfo.creditCode }}
          </el-descriptions-item>

          <!-- 第二行 -->
          <el-descriptions-item label="企业类型">
            {{ transformDict('enterpriseType', enterpriseInfo.enterpriseNature) }}
          </el-descriptions-item>
          <el-descriptions-item label="企业人数">
            {{ transformDict('numberOfCompany', enterpriseInfo.staffNum) }}
          </el-descriptions-item>

          <!-- 第三行 -->
          <el-descriptions-item label="所属行业">
            {{ enterpriseInfo.industry }}
          </el-descriptions-item>
          <el-descriptions-item label="注册资本">
            {{ enterpriseInfo.registeredCapital }}万
          </el-descriptions-item>

          <!-- 第四行 -->
          <el-descriptions-item label="是否小微企业">
            {{ transformDict('microFlag', enterpriseInfo.microFlag) }}
          </el-descriptions-item>
          <el-descriptions-item label="开户行">
            {{ transformDict('bank', enterpriseInfo.depositBank) }}
          </el-descriptions-item>

          <!-- 第五行 -->
          <el-descriptions-item label="注册地所在区域">
            {{ enterpriseInfo.provinceName }}/{{ enterpriseInfo.cityName }}/{{ enterpriseInfo.areaName }}
          </el-descriptions-item>
          <el-descriptions-item label="经营地所在区域">
            {{ enterpriseInfo.corrProvinceSiteName }}/{{ enterpriseInfo.corrCitySiteName }}/{{
              enterpriseInfo.corrAreaSiteName }}
          </el-descriptions-item>

          <!-- 第六行 -->
          <el-descriptions-item label="注册地址">
            {{ enterpriseInfo.legalAddress }}
          </el-descriptions-item>
          <el-descriptions-item label="经营地址">
            {{ enterpriseInfo.corrAddress }}
          </el-descriptions-item>

          <!-- 第七行 -->
          <el-descriptions-item label="持续经营年限">
            {{ enterpriseInfo.durationManagement }}
          </el-descriptions-item>
          <el-descriptions-item label="单位电话">
            {{ enterpriseInfo.workTelephone }}
          </el-descriptions-item>

          <!-- 第八行 -->
          <el-descriptions-item label="联系姓名">
            {{ enterpriseInfo?.legal?.name }}
          </el-descriptions-item>
          <el-descriptions-item label="联系手机">
            {{ enterpriseInfo?.legal?.mobile }}
          </el-descriptions-item>
        </el-descriptions>

        <el-descriptions label-width="200" title="企业经营信息" :column="2" border size="medium"
          class="mt-10 financial-descriptions">
          <!-- 第一行 -->
          <el-descriptions-item label="营业场所性质">
            {{ transformDict('businessPremises', enterpriseInfo.businessPlace) }}
          </el-descriptions-item>
          <el-descriptions-item label="上年度开票营业收入">
            {{ enterpriseInfo.lastYearInvoiceRevenue }}
          </el-descriptions-item>

          <!-- 第二行 -->
          <el-descriptions-item label="上年度纳税金额">
            {{ transformDict('taxAmount', financingInfo.taxAmount) }}
          </el-descriptions-item>
          <el-descriptions-item label="上年度报关成交额">
            {{ enterpriseInfo.declareDeal }}万
          </el-descriptions-item>

          <!-- 第三行 -->
          <el-descriptions-item label="纳税等级">
            {{ transformDict('ratepayingLevel', enterpriseInfo.taxLevel) }}
          </el-descriptions-item>
          <el-descriptions-item label="近一年企业盈亏状态">
            {{ transformDict('enterpriseProfit', enterpriseInfo.profitState) }}
          </el-descriptions-item>

          <!-- 第四行 -->
          <el-descriptions-item label="连续纳税年限">
            {{ enterpriseInfo.taxYears }}
          </el-descriptions-item>
          <el-descriptions-item label="抵押物类型">
            {{ transformDict('pawnType', financingInfo.collateralFlag) }}
          </el-descriptions-item>

          <!-- 第五行 -->
          <el-descriptions-item label="之前贷款银行">
            {{ transformDict('bank', financingInfo.loanBankName) }}
          </el-descriptions-item>
          <el-descriptions-item label="当前贷款余额">
            {{ financingInfo.loanLeftAmount }}万
          </el-descriptions-item>
        </el-descriptions>

        <el-descriptions label-width="200" border :column="2" class="mt-10" title="法定代表人/个人工商户经营者信息">
          <el-descriptions-item label="法定代表人/经营者">
            {{ enterpriseInfo?.legal?.name }}
          </el-descriptions-item>
          <el-descriptions-item label="现居住地">
            {{ enterpriseInfo?.legal?.legalLiveAddress }}
          </el-descriptions-item>
          <el-descriptions-item label="从业年限">
            {{ enterpriseInfo?.legal?.employmentYears }}
          </el-descriptions-item>
          <el-descriptions-item label="持股比例">
            {{ enterpriseInfo?.legal?.shareholdingRatio }}%
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="企业信用报告" name="creditReport">
      </el-tab-pane>
      <el-tab-pane label="企业关系图谱" name="related">
      </el-tab-pane>
      <el-tab-pane label="历史对接记录" name="history">
      </el-tab-pane>
    </el-tabs>


    <el-tabs class="mt-5" v-model="infoActive" @tab-click="handleInfoClick">
      <el-tab-pane label="授信信息" name="credit">
        <el-descriptions title="授信信息" :column="2" border size="medium" class="credit-approval-descriptions">
          <!-- 第一行 -->
          <el-descriptions-item label="授信机构">
            {{ creditInfo?.organizationName }}
          </el-descriptions-item>
          <el-descriptions-item label="授信金额（万）">
            {{ creditInfo?.creditAmount }}
          </el-descriptions-item>

          <!-- 第二行 -->
          <el-descriptions-item label="授信期限（月）">
            {{ creditInfo?.creditPeriod }}月
          </el-descriptions-item>
          <el-descriptions-item label="授信利率（%）">
            {{ creditInfo?.realRate }}%
          </el-descriptions-item>

          <!-- 第三行 -->
          <el-descriptions-item label="还款方式">
            {{ creditInfo?.paymentType }}
          </el-descriptions-item>
          <el-descriptions-item label="授信时间">
            {{ creditInfo?.creditTime }}
          </el-descriptions-item>

          <!-- 第四行：备注通常占一整行 -->
          <el-descriptions-item label="备注" :span="2">
            {{ creditInfo.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="用信信息" name="use">
        <el-table border :data="loadDataList">
          <el-table-column label="用信金额（万元)" prop="loanAmount"></el-table-column>
          <el-table-column label="用信期限（月）" prop="loanPeriod"></el-table-column>
          <el-table-column label="用信利率（%）" prop="loanRate"></el-table-column>
          <el-table-column label="还款方式" prop="paymentType"
            :formatter="(row) => transformDict('repaymentType', row.paymentType)"></el-table-column>
          <el-table-column label="用信时间" prop="loanTime"></el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="还款信息" name="repay">
        <el-table border :data="repayDataList">
          <el-table-column label="还款类型" prop="repaymentType"
            :formatter="(row) => transformDict('paymentType', row.repaymentType)"></el-table-column>
          <el-table-column label="还款金额（万元）" prop="repaymentAmount"></el-table-column>
          <el-table-column label="还款时间" prop="repaymentTime"></el-table-column>
          <el-table-column label="备注" prop="remark"></el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="进度日志" name="log">
      </el-tab-pane>
    </el-tabs>

  </div>
</template>
<script setup lang="ts">
import { getCreditLoanRepayMent, getfinancingInfo } from '@/api/order'
import { useDict, transformDict } from '@/hooks/dict'
const route = useRoute()
useDict('businessPremises', 'taxAmount', 'ratepayingLevel', 'enterpriseProfit', 'pawnType', 'bank', 'enterpriseType', 'numberOfCompany', 'microFlag', 'paymentType', 'repaymentType');


function handleCompanyClick() {

}
function handleInfoClick() { }



const creditInfo = reactive({})
const loadDataList = ref([])
const repayDataList = ref([])
function getCreditLoanRepayMentFun() {
  getCreditLoanRepayMent({
    orderNo: route.query.orderNo,
  }).then(res => {
    console.log(res)
    Object.assign(creditInfo, res.data.orderCredit)
    loadDataList.value = res.data.ocOrderLoans
    repayDataList.value = res.data.orderRepayments
  })
}
const enterpriseInfo = reactive({})
const financingInfo = reactive({})
function getfinancingInfoFun() {
  getfinancingInfo({
    appId: route.query.applyNo,
  }).then(res => {
    Object.assign(enterpriseInfo, res.data.enterpriseInfo)
    Object.assign(financingInfo, res.data.financingInfo)
    console.log(res)
  })
}

onMounted(() => {
  getCreditLoanRepayMentFun()
  getfinancingInfoFun()
})

const companyActive = ref('baseInfo')
const infoActive = ref('credit')
</script>

<style lang="scss" scoped>
@use '@/assets/styles/tabs_ui.scss';
</style>
